package com.dorm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dorm.entity.Student;
import com.dorm.mapper.StudentMapper;
import com.dorm.service.StudentService;
import org.springframework.stereotype.Service;

/**
 * 学生服务实现类
 */
@Service
public class StudentServiceImpl extends ServiceImpl<StudentMapper, Student> implements StudentService {

    @Override
    public Page<Student> pageQuery(Integer pageNum, Integer pageSize, String studentNo, String name, String className) {
        Page<Student> page = new Page<>(pageNum, pageSize);
        LambdaQueryWrapper<Student> wrapper = new LambdaQueryWrapper<>();
        
        if (studentNo != null && !studentNo.isEmpty()) {
            wrapper.like(Student::getStudentNo, studentNo);
        }
        if (name != null && !name.isEmpty()) {
            wrapper.like(Student::getName, name);
        }
        if (className != null && !className.isEmpty()) {
            wrapper.like(Student::getClassName, className);
        }
        
        wrapper.orderByDesc(Student::getCreateTime);
        return page(page, wrapper);
    }
}

